<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* 实训
*/
class Shixun extends MY_Controller {

	public function index()
	{	
		$data = json_decode(file_get_contents("http://123.206.137.187:804/HandlerData.ashx?action=GetZhangtaoInfo"),true);
		$shixun_data = $shixun_list = array();
		if(!empty($data['rows']) && count($data['rows']) > 0){
			$this->load->model("Shixuns");
			$ids = '';
			foreach ($data['rows'] as $key => $value) {
				$shixun_list[$value['Id']] = $value;
				if($key == 0){
					$ids .= "'" . $value['Id'] . "'";
				}else{
					$ids .= ",'" . $value['Id'] . "'";
				}
			}
			$pack_list = $this->Shixuns->get_sx_packages($ids);
			if($pack_list){
				foreach ($pack_list as $k => $v) {
					if(isset($shixun_list[$v['sx_id']]) && $v['status'] == 1){
						$shixun_list[$v['sx_id']]['status'] = $v['status'];
						$shixun_list[$v['sx_id']]['pack_id'] = $v['id'];
						$shixun_data[] = $shixun_list[$v['sx_id']];
					}
				}
			}
		}
		$this->load->model('Advertisings');
        $ad_conditions['ad_position_sign'] = "shixun-banner";
        $ad_conditions['school_id'] = $this->school_id;
        $banner_list = $this->Advertisings->get_list($ad_conditions);

		// print_r($shixun_list);
		$this->smarty->assign("menu", "shelves");
		$this->smarty->assign("shixun_list", $shixun_data);
		$this->smarty->assign("banner_list", $banner_list);
		$this->smarty->assign("menu_id", 6);
		$this->smarty->display("shixun/index.html");
	}

	function check_shixun_order(){
		if(empty($this->user_data)){
			echo -1;exit;
		}
		$post_data = $this->input->post();
		if(empty($post_data['sx_id'])){
			header("Location:/shixun");exit;
		}
		$this->load->model("Order_model");
		$order_info = $this->Order_model->get_sx_order($post_data['sx_id'], $this->user_data['id'], $this->school_id);
		$buy_status = 0;
		if(!empty($order_info)){
			$buy_status = 1;
		}
		echo $buy_status;
	}

	function create_sx_order(){
		if(empty($this->user_data)){
			echo -1;exit;
		}
		$post_data = $this->input->post();
		if(empty($post_data['sx_id'])){
			echo 0;
		}else{
			$this->load->model('Order_model');
			$settle_id = $this->Order_model->buy_now($this->user_data['id'],$post_data['sx_id'],1,5);
			echo $settle_id;
		}
	}
}
